package by.artureg.so.conf;

import by.artureg.so.ex.SoException;
import org.apache.log4j.Logger;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

import java.io.File;
import java.net.URL;

public class ConfLoader {
    private static final Logger logger = Logger.getLogger(ConfLoader.class);
    private static ConfLoader confLoader;
    private Config config;

    private ConfLoader() throws SoException {
        Serializer serializer = new Persister();
        URL resource = this.getClass().getClassLoader().getResource("reports.xml");
        File source = new File(resource.getPath());

        try {
            this.config = serializer.read(Config.class, source);
        } catch (Exception e) {
            throw new SoException(e);
        }

    }

    public static Config load() throws SoException {
        //if (confLoader == null) {
            confLoader = new ConfLoader();
        //}
        return confLoader.config;
    }

    public static void main(String[] args) throws SoException {
        ConfLoader.load();
    }


}
